package org.hxzon.cyclone.plinks;

import java.util.List;

import org.hxzon.cyclone.Particle;
import org.hxzon.cyclone.Vector3;
import org.hxzon.cyclone.pcontacts.ParticleContact;
import org.hxzon.cyclone.pcontacts.ParticleContactGenerator;

//粒子约束，联接的一点固定
public abstract class ParticleConstraint implements ParticleContactGenerator {
    public Particle particle;

    //约束的固定点
    public Vector3 anchor;

    protected double currentLength() {
        Vector3 relativePos = particle.getPosition().minus(anchor);
        return relativePos.magnitude();
    }

    /**
    * Geneates the contacts to keep this link from being
    * violated. This class can only ever generate a single
    * contact, so the pointer can be a pointer to a single
    * element, the limit parameter is assumed to be at least one
    * (zero isn't valid) and the return value is either 0, if the
    * cable wasn't over-extended, or one if a contact was needed.
    *
    * NB: This method is declared in the same way (as pure
    * virtual) in the parent class, but is replicated here for
    * documentation purposes.
    */
    public abstract int addContact(List<ParticleContact> contacts);

}
